import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_acceess_card_component/component.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_acceess_card_component/state.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_access_robbit_component/component.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_access_robbit_component/state.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_grid_component/component.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_grid_component/state.dart';

import 'effect.dart';
import 'reducer.dart';
import 'state.dart';
import 'view.dart';

class CompanyComponent extends Component<CompanyState> {
  CompanyComponent()
      : super(
          effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
          dependencies: Dependencies<CompanyState>(
              adapter: null,
              slots: <String, Dependent<CompanyState>>{
                'village-access':
                    _VillageAccessConnecter() + VillageAccessRobbitComponent(),
                'village-access-card': _VillageAccessCardConnecter() +
                    VillageAcceessCardComponent(),
                'village-grid':
                    _VillageGridConnecter() + VillageGridComponent(),
              }),
        );
  @override
  ComponentState<CompanyState> createState() {
    return _CompanySingleTickerProviderState();
  }
}

class _CompanySingleTickerProviderState extends ComponentState<CompanyState>
    with SingleTickerProviderStateMixin {}

class _VillageAccessConnecter
    extends ConnOp<CompanyState, VillageAccessRobbitState> {
  var _robbitState = VillageAccessRobbitState();
  @override
  VillageAccessRobbitState get(CompanyState state) {
    _robbitState.build = state.build;
    _robbitState.unit = state.unit;
    _robbitState.house = state.house;
    return _robbitState;
  }

  @override
  void set(CompanyState state, VillageAccessRobbitState subState) {
    _robbitState = subState;
  }
}

class _VillageAccessCardConnecter
    extends ConnOp<CompanyState, VillageAcceessCardState> {
  var _cardState = VillageAcceessCardState();
  @override
  VillageAcceessCardState get(CompanyState state) {
    _cardState.build = state.build;
    _cardState.unit = state.unit;
    _cardState.house = state.house;
    return _cardState;
  }

  @override
  void set(CompanyState state, VillageAcceessCardState subState) {
    _cardState = subState;
  }
}

class _VillageGridConnecter extends ConnOp<CompanyState, VillageGridState> {
  var _gridState = VillageGridState();
  @override
  VillageGridState get(CompanyState state) {
    _gridState.build = state.build;
    _gridState.unit = state.unit;
    _gridState.house = state.house;
    return _gridState;
  }

  @override
  void set(CompanyState state, VillageGridState subState) {
    _gridState = subState;
  }
}
